package com.shanzmoo.h5.domain.vo;

import cn.hutool.core.util.NumberUtil;
import com.shanzmoo.db.product.entity.dto.ProductSpuDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @author Administrator
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@ApiModel("商品搜索详情")
public class ProductSpuBriefVo implements Serializable {
    private static final long serialVersionUID = 1758L;

    @ApiModelProperty("商品编码")
    private String spu;

    @ApiModelProperty("商品名称")
    private String spuName;

    @ApiModelProperty("图片")
    private String pictureUrl;

    @ApiModelProperty("商品销量")
    private Integer salesCount;

    @ApiModelProperty("副标题")
    private String subheading;

    @ApiModelProperty("商品展示价格")
    private BigDecimal retailPrice;

    public static ProductSpuBriefVo create(ProductSpuDto spuDto, Integer actualSales) {

        return ProductSpuBriefVo.builder()
                .spu(spuDto.getSpu())
                .spuName(spuDto.getName())
                .pictureUrl(spuDto.getPictureUrl())
                .subheading(spuDto.getSubheading())
                .salesCount(NumberUtil.add(spuDto.getBaseSales(), actualSales).intValue())
                .retailPrice(spuDto.getRetailPrice())
                .build();
    }
}
